<?php
require_once('../includes/db.php');

class Cms_Controller
{
	protected $_render = true;
	
	public function __construct()
	{
		$this->init();
	}
	
	/* To be overridden by the subclass */
	public function init()
	{
		
	}
	
	public function render($request)
	{
		if($this->_render) {
			$controllerPath =  strtolower(preg_replace('/Controller/', '' ,$request['Controller']));
			$actionPath =  strtolower(preg_replace('/Action/', '' ,$request['Action'])); 
			require_once($request['Module'] . "/views/".$controllerPath . '/' . $actionPath . ".html");
		}
		
	}
	
	public function sendJson($jsonData = null)
	{
		$this->_render = false;
		echo json_encode($jsonData);
	}
	
	/**
	 * Check if any Post parameters have been sent
	 *
	 * return boolan if and only if Post parameters have been sent
	 */
	public function checkPost()
	{
		if(!isset($_POST)) {
			return false;
		}
		
		return true;
	}
}
?>